package com.easy.controller;

import com.easy.bean.Employee_attendance;
import com.easy.service.EmployeeAttendanceService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/api/attendance")
public class EmployeeAttendanceController {

    @Autowired
    EmployeeAttendanceService attendanceService;

    @PostMapping
    public Result add(@RequestBody Employee_attendance attendance) {
        return Result.success(attendanceService.add(attendance));
    }

    @PutMapping("/{id}")
    public Result edit(@PathVariable("id") Integer id, @RequestBody Employee_attendance attendance) {
        attendance.setId(id);
        return Result.success(attendanceService.edit(attendance));
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable("id") Integer id) {
        return Result.success("删除数据", attendanceService.del(id));
    }

    @GetMapping
    public Result all(@RequestParam(name = "employee_id", required = false) Integer employee_id) {
        return Result.success(attendanceService.all(employee_id));
    }

    @GetMapping("/{id}")
    public Result one(@PathVariable("id") Integer id) {
        return Result.success(attendanceService.one(id));
    }

    @GetMapping("page")
    public Result page(Page page, Employee_attendance attendance){
        attendanceService.page(page, attendance);
        return Result.success(page);
    }
}
